import { DatePipe } from '@angular/common';
import { BusiProvider } from './../../providers/busi/busi';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { NativeProvider } from '../../providers/native/native';
import * as moment from "moment"
/**
 * Generated class for the UsereditPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-useredit',
  templateUrl: 'useredit.html',
})
export class UsereditPage {
  userid:any;
  username:any;
  xm:any;
  age:any;
  address:any;
  email:any;
  sjhm:any;
  datePipe: DatePipe = new DatePipe("en");
  constructor(public navCtrl: NavController, public navParams: NavParams,private busi: BusiProvider,private native: NativeProvider) {
    this.busi.getUserInfo().subscribe(
      data=>{
        const userinfo = data.userinfo;
        this.userid = userinfo.userid;
        this.username = userinfo.username;
        this.xm = userinfo.xm;
        this.age = userinfo.age;
        this.address = userinfo.address;
        this.email = userinfo.email;
        this.sjhm = userinfo.sjhm;


      },error=>{

      }
    );
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad UsereditPage');
  }

  save(){
    let body = {
      userid: this.userid,
      username: this.username,
      xm: this.xm,
      age: this.age,
      address: this.address,
      email: this.email,
      sjhm: this.sjhm
    }
    this.busi.appUserModify(body).subscribe(
      ()=>{
        this.native.showToast("保存成功!");
        this.navCtrl.pop();
      },
      error=>{

      }
    );
  }

}
